<?php
	include_once ('db.conf');

/* Connect to a MySQL server */
$link = mysqli_connect(DBHOST,DBUSER,DBPASS,DBDBNAME);
		
		$userlogin=$_POST["login"];
		$password=$_POST["password"];
		
		
		$userIsBlocked =true;
		$passIsOk=false;
		
		$query="call getBlockedCustomer('".$userlogin."');";
		$count=0;
		if($result = mysqli_query($link,$query ))
			while( $row = mysqli_fetch_assoc($result) ){
     			$count ++;   
    	}
		
		mysqli_close($link); 
		
		if($count !=0){$userIsBlocked = true;}else $userIsBlocked = false;
		$link = mysqli_connect(DBHOST,DBUSER,DBPASS,DBDBNAME);
		$query="call getCustomer('".$userlogin."');";
		$num_rows=0;
		if($result = mysqli_query($link,$query ))
			while( $row = mysqli_fetch_assoc($result) ){
     			$num_rows ++;
				
			$passwordfromDB=$row['passwd'];
			$firstname=$row['firstName'];
			$lastname=$row['lastName'];
			$points=$row['points'];
			$banknumber=$row['accountNr'];
			$email=$row['email'];
			$birthyear=$row['birthyear'];
			$gender=$row['gender'];   
    	}
		
		if ($num_rows != 0){ 
			

			if($passwordfromDB==$password)$passIsOk = true;

		}
		//if($userIsBlocked)echo User_is_blocked;else echo User_is_not_blocked;
		//if($passIsOk)echo Password_is_OK;else echo Password_is_not_OK;
		
		if($passIsOk){ //password is OK, so we have to check if the acount is blocked or not
			if($userIsBlocked){//the user is blocked, so we will show him the form form unblock it
			
			echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to customers interface</title>

<script type="text/javascript" language="JavaScript"><!--
function kontrola()
{
	var activlogin = self.document.forms.form1.activlogin.value;
	var activcode = self.document.forms.form1.activcode.value;

    var is_ok = false;
    if ((activlogin != "")&&(activcode != "")) is_ok = true;
	
	
	if (is_ok == false) alert("Sorry something is wrong or missing!");
    return is_ok; }
// -->
</script>


<style type="text/css">
<!--
.style5 {color: #0066FF; font-size: 24px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
.style7 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #0066FF;
}
.style8 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #FFFFFF;
}
.style12 {
	font-size: 18;
}
.style17 {font-size: 16px}
.style18 {font-family: Arial, Helvetica, sans-serif}
.style20 {color: #FFFFFF}
.style21 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>

<body>
<p><img src="pics/main_logo_with_text_1010x12.gif" width="1010" height="124" /></p>
<table width="100%" border="0">
  <tr>
    <td colspan="2" align="left" bgcolor="#FF9900"><blockquote>
      <p><span class="style5"> Account not activated yet :-(</span></p>
    </blockquote></td>
  </tr>
  <tr>
    <td width="76%" rowspan="3" align="center" valign="top"><blockquote>
      <p align="justify" class="style7">&nbsp;</p>
      <p align="justify" class="style7">We are sorry, but your account was not activated yet. Use the activation code.</p>
      </blockquote></td>
    <td width="24%" valign="top" bgcolor="#FF9900"><div align="center" class="style8">
      <p class="style12">account activation
        <label></label>
      </p>
      <form onSubmit="return kontrola();" action="unblockaccount.php" method="post" name="form1" class="style12" id="form1">
        <p>                                      
          <span class="style17">
          <label>cell</label> <br />
          <input name="activlogin" type="text" id="activlogin" />
          <br />
          <label>code</label><br />
          <input name="activcode" type="text" id="activcode" />
          </span>        </p>
        <p>
          <label>
            <input type="submit" name="send" id="send" value="Submit" />
            </label>
        </p>
      </form>
      </div>      </td>
  
  
</table>
</body>
</html>';
			
			}else{//the password is OK and he is not blocked, so show him his name, points and form for change his data
			
			echo'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New customer registration</title>

<script type="text/javascript" language="JavaScript"><!--
function kontrola()
{
	var cell = self.document.forms.form1.cellnum.value;
	var email = self.document.forms.form1.email.value;
	var bankaccount = self.document.forms.form1.bankaccount.value;
	var regpassword = self.document.forms.form1.regpassword.value;
	var regretypepassword = self.document.forms.form1.regretypepassword.value;

	
	
	
	
    var is_ok = false;
    if ((cell != "")&&(email != "")&&(bankaccount != "")&&(regpassword != "")&&(regpassword ==regretypepassword )) is_ok = true;
	
    
    
    
    if(is_ok) //the email structure validation
	    {
	       	var at="@"
		var dot="."
		var lat=email.indexOf(at)
		var lstr=email.length
		var ldot=email.indexOf(dot)

		if (email.indexOf(at)==-1)	   is_ok = false;
		if (email.indexOf(at)==-1 || email.indexOf(at)==0 || email.indexOf(at)==lstr) is_ok = false;
		if (email.indexOf(dot)==-1 || email.indexOf(dot)==0 || email.indexOf(dot)==lstr) is_ok = false;
		if (email.indexOf(at,(lat+1))!=-1)   is_ok = false;
		if (email.substring(lat-1,lat)==dot || email.substring(lat+1,lat+2)==dot)   is_ok = false;
		if (email.indexOf(dot,(lat+2))==-1) is_ok = false;
		if (email.indexOf(" ")!=-1)  is_ok = false;
	    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
	
	if (is_ok == false) alert("Sorry something is wrong or missing!");
    return is_ok; }
// -->
</script>


<style type="text/css">
<!--
.style5 {color: #0066FF; font-size: 24px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
.style7 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #0066FF;
}
.style8 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #FFFFFF;
}
.style12 {
	font-size: 18;
}
.style17 {font-size: 16px}
.style18 {font-family: Arial, Helvetica, sans-serif}
.style20 {color: #FFFFFF}
-->
</style>
</head>

<body>
<p><img src="pics/main_logo_with_text_1010x12.gif" width="1010" height="124" /></p>
<table width="100%" border="0">
  <tr>
    <td colspan="2" align="left" bgcolor="#FF9900"><blockquote>
      <p><span class="style5"> Hello ';
	  echo $firstname;
	  
	 /* 			$userlogin
			$passwordfromDB=mysql_result($result, 0, "passwd");
			$firstname=mysql_result($result, 0, "firstName");
			$lastname=mysql_result($result, 0, "lastName");
			$points=mysql_result($result, 0, "point");
			$banknumber=mysql_result($result, 0, "accountNr");
			$email=mysql_result($result, 0, "email");
			$birthyear=mysql_result($result, 0, "birthyear");
			$gender=mysql_result($result, 0, "gender");

	  */
	  
	  
	  echo', you have ';
	  echo $points;
	  
	  echo' points on your account:-)</span></p>
    </blockquote></td>
  </tr>
  <tr>
    <td width="25%" rowspan="3" align="center" valign="top"><div align="left">
      <blockquote>&nbsp; </blockquote>
    </div>      <blockquote>
      <p align="left" class="style7">Here you can change you detail.</p>
    </blockquote></td>
    <td width="75%" valign="top" bgcolor="#FF9900"><div align="center" class="style8">
      <p class="style12">
        <label></label><span class="style17">
        <label></label> 
          </span></p>
      <form  name="form1" onSubmit="return kontrola();" action="updateaccount.php" method="post"  class="style12">
        <table width="322" border="0">
          <tr>
            <td width="7"><div align="right"><span class="style17">*</span></div></td>
            <td width="149"><div align="right"><span class="style17">cell number</span></div></td>
            <td width="152"><label>
              <input name="points" type="hidden" id="points" value="';
			  echo $points;
			  echo'" />
			  <input name="cellnum" type="text" id="cellnum" value="';
			  echo $userlogin;
			  
			  echo'" maxlength="20" readonly="true" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td><div align="right"><span class="style17">first name</span></div></td>
            <td><label>
              <input name="firstname" type="text" id="firstname" value="';
			  echo $firstname;
			  echo'" maxlength="30" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td><div align="right"><span class="style17">last name</span></div></td>
            <td><label>
              <input name="lastname" type="text" id="lastname" value="';
			  echo $lastname;
			  echo'" maxlength="30" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"><span class="style17">*</span></div></td>
            <td><div align="right"><span class="style17">email</span></div></td>
            <td><label>
              <input name="email" type="text" id="email" value="';
			  echo $email;
			  echo'" maxlength="50" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td><div align="right"><span class="style17">year of birth</span></div></td>
            <td><label>
              <input name="yearofbirth" type="text" id="yearofbirth" value="';
			  echo $birthyear;
			  echo'" maxlength="4" />
              </label></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><div align="right"><span class="style17">gender</span></div></td>
            <td align="center" valign="middle"><p class="style17">
              <label>
               	  <input type="radio" name="gender" value="f" id="gender_0" ';
				  
				  if ($gender=='f')echo 'checked="checked"';
				  echo'/>
                girl</label>
              <label>
                <input name="gender" type="radio" id="gender_1" value="m" ';
				  
				  if ($gender=='m')echo 'checked="checked"';
				  echo' />
                boy</label>
              <br />
            </p>              
              <label></label></td>
          </tr>
          <tr>
            <td><div align="right"><span class="style17">*</span></div></td>
            <td><div align="right"><span class="style17">bank account number</span></div></td>
            <td><label>
              <input name="bankaccount" type="text" id="bankaccount" value="';
			  echo $banknumber;
			  
			  echo'" maxlength="30" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"><span class="style17">*</span></div></td>
            <td><div align="right"><span class="style17">password</span></div></td>
            <td><label>
              <input name="regpassword" type="password" id="regpassword" value="';
			  echo $passwordfromDB;
			  echo'" maxlength="30" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"><span class="style17">*</span></div></td>
            <td><div align="right"><span class="style17">retype password</span></div></td>
            <td><label>
              <input name="regretypepassword" type="password" id="regretypepassword" value="';
			  echo $passwordfromDB;
			  echo'" maxlength="30" />
            </label></td>
          </tr>
          <tr>
            <td><div align="right"></div></td>
            <td><div align="right"></div></td>
            <td><label>
              <div align="center">
                <input type="submit" name="send2" id="send2" value="submit" />
                <input type="reset" name="reset" id="reset" value="reset" />
              </div>
            </label></td>
          </tr>
        </table>
        <div align="left"></div>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        </form>
      </div>      </td>
  </tr>
  <tr>
    <td bgcolor="#FF9900" class="style12"><div align="center" class="style18">
      <p class="style12"><span class="style20">or contact us at</span> <a href="mailto:psi2@iot.sdu.dk?subject=Forgotten password :-(&body=Here write your story about forgotten password..." class="style20">psi2@iot.sdu.dk</a></p>
    </div></td>
  </tr>
  
  
  
  
  
  
</table>
</body>
</html>
';
			
			}
		
		
		}else{// the password is not OK, so we will not check if the user is blocked,just write, you are wrong,try again
		echo'
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to customers interface</title>
<style type="text/css">
<!--
.style5 {color: #0066FF; font-size: 24px; font-family: Arial, Helvetica, sans-serif; font-weight: bold; }
.style7 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #0066FF;
}
.style8 {
	font-size: 24px;
	font-family: Arial, Helvetica, sans-serif;
	color: #FFFFFF;
}
.style12 {
	font-size: 18;
}
.style17 {font-size: 16px}
.style18 {font-family: Arial, Helvetica, sans-serif}
.style20 {color: #FFFFFF}
.style21 {color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; }
-->
</style>
</head>

<body>
<p><img src="pics/main_logo_with_text_1010x12.gif" width="1010" height="124" /></p>
<table width="100%" border="0">
  <tr>
    <td colspan="2" align="left" bgcolor="#FF9900"><blockquote>
      <p><span class="style5"> Not right :-(</span></p>
    </blockquote></td>
  </tr>
  <tr>
    <td width="76%" rowspan="3" align="center" valign="top"><blockquote>
      <p align="justify" class="style7">&nbsp;</p>
      <p align="justify" class="style7">We are sorry, but your login or password is not right, try it again or use send forgoten password function.</p>
      </blockquote></td>
    <td width="24%" valign="top" bgcolor="#FF9900"><div align="center" class="style8">
      <p class="style12">registered users
        <label></label>
      </p>
      <form action="main.php" method="post" name="form1" class="style12" id="form1">
        <p>                                      
          <span class="style17">
          <label>login</label> <br />
          <input name="login" type="text" id="userlogin" />
          <br />
          <label>password</label><br />
          <input name="password" type="password" id="password" />
          </span>        </p>
        <p>
          <label>
            <input type="submit" name="send" id="send" value="Submit" />
            </label>
        </p>
      </form>
      </div>      </td>
  </tr>
  <tr>
    <td bgcolor="#FF9900" class="style12"><div align="center" class="style18"><a href="forgottpass.html" class="style20">forgotten password</a></div></td>
  </tr>
  <tr>
    <td bgcolor="#FF9900" class="style12"><div align="center" class="style18"><a href="register.html" class="style20">register new customer</a></div></td>
  </tr>
  
</table>
</body>
</html>
		
		';
		
		}
		


		?>